#include "../../tedi2lang/dessert.hpp"
#include "../../tedi2lang/tedi2lang.h"
#include "../tedi2ad.h"
#include "../../tedi2lang/exception.h"
#include <string>
#include <cstring>
#include <iostream>
int main(){
	
	tedi2ad td;

	//Empty string
	cout << "EMPTY STRINGS" << endl;

	dessert((td.convert("", "", "")) == (""));

	dessert(td.convert(" ", "", "") == (" \n"));
	dessert(td.convert("\n\n\n", "", "") == ("\n\n\n"));

	//Titles
	cout << "TITLES" << endl;

	dessert(throws(td.convert("#####", "", "")));
	dessert(td.convert("paragraph\n#This isn't a title", "", "") == ("paragraph\n= This isn't a title\n"));

	dessert(td.convert("#This isn't a title", "", "") == ("= This isn't a title\n"));
	dessert(td.convert(" #This isn't a title", "", "") == ("= This isn't a title\n"));
	dessert(td.convert("\t##This isn't a title", "", "") == ("== This isn't a title\n"));

	dessert(td.convert("##This isn't a title", "", "") == ("== This isn't a title\n"));
	dessert(td.convert("###This isn't a title", "", "") == ("=== This isn't a title\n"));
	dessert(td.convert("####This isn't a title", "", "") == ("==== This isn't a title\n"));
	dessert(td.convert("#####This isn't a title", "", "") == "==== This isn't a title\n" );
	dessert(td.convert("#####This isn't a title", "", "") == "==== This isn't a title\n" );

	cout << "LIST" << endl;

	dessert(td.convert("__", "", "") == ("\n"));
	dessert(td.convert("--Text", "", "") == ("--Text\n"));
	dessert(td.convert(",,", "", "") == (",,\n"));
	dessert(td.convert("__\n--Text\n,,", "", "") == ("\n* Text\n\n"));

	cout << "QUOTE" << endl;

	dessert(td.convert("\"Quoted text\"", "", "") == ("Quoted text\n"));
	dessert(throws(td.convert("\"Bad quoting", "", "")));

	cout << "LINKS" << endl;

	dessert(td.convert("[Test with a open square bracket", "", "") == ("[Test with a open square bracket\n"));
	dessert(throws(td.convert("[(Test with a open square bracket and parenthesis", "", "")));
	dessert(throws(td.convert("[(Test without closing square bracket)", "", "")));
	dessert(throws(td.convert("[(Test with closing square bracket)]", "", "")));
	dessert(td.convert("[(Test with closing square bracket) ]", "", "") == "Test with closing square bracket[]\n");

	dessert(td.convert("[() ]", "", "") == "[]\n");
	dessert(td.convert("[( ) ]", "", "") == " []\n");

	dessert(throws(td.convert("[(test\\) test with escaped char\\) ]", "", "")));

	dessert(td.convert("[(test\\) test with escaped char) ]", "", "") == "test) test with escaped char[]\n");
	dessert(td.convert("[(test\\) test with escaped char) \\]sasdfasd]", "", "") == "test) test with escaped char[]sasdfasd]\n");
	dessert(td.convert("[(test\\( test with escaped char) \\]sasdfasd]", "", "") == "test( test with escaped char[]sasdfasd]\n");

	dessert(td.convert("\\[(Test with closing square bracket) text", "", "") == "[(Test with closing square bracket) text\n");
	dessert(td.convert("\\[( [(Test with closing square bracket) text]", "", "") == "[( Test with closing square bracket[text]\n");

	cout << "IMAGES" << endl;

	dessert(td.convert("(Test with an open parenthesis", "", "") == ("(Test with an open parenthesis\n"));
	
	dessert(throws(td.convert("([Test with a open square bracket and parenthesis", "", "")));
	dessert(throws(td.convert("([Test without closing square bracket]", "", "")));

	dessert(throws(td.convert("([Test with closing square bracket])", "", "")));
	dessert(td.convert("([Test with closing square bracket] )", "", "") == "image::[Test with closing square bracket]\n");
	dessert(td.convert("([] )", "", "") == "image::[]\n");
	dessert(td.convert("([ ] )", "", "") == "image::[ ]\n");

	dessert(throws(td.convert("([test\\] test with escaped char\\] )", "", "")));
	dessert(td.convert("([test\\] test with escaped char] )", "", "") == "image::[test] test with escaped char]\n");
	dessert(td.convert("([test\\] test with escaped char] \\)sasdfasd)", "", "") == "image::)sasdfasd[test] test with escaped char]\n");

	dessert(td.convert("\\([Test with closing square bracket) text", "", "") == "([Test with closing square bracket) text\n");
	dessert(td.convert("\\([ ([Test with closing square bracket] text)", "", "") == "([ image::text[Test with closing square bracket]\n");


	cout << "BLOCKS" << endl;

	dessert(td.convert("{Test with an open parenthesis", "", "") == ("{Test with an open parenthesis\n"));
	dessert(throws(td.convert("{(Test with a open square bracket and parenthesis", "", "")));
	dessert(throws(td.convert("{(Test without closing square bracket)", "", "")));
	dessert(throws(td.convert("{(Test with closing square bracket)}", "", "")));
	dessert(td.convert("{(Test with closing square bracket) }", "", "") == "\n");
	dessert(td.convert("{() }", "", "") == "\n");
	dessert(td.convert("{( ) }", "", "") == "\n");

	dessert(throws(td.convert("{(test\\) test with escaped char\\) }", "", "")));
	dessert(td.convert("{(test\\) test with escaped char) }", "", "") == "\n");
	dessert(td.convert("{(test\\) test with escaped char) \\}sasdfasd}", "", "") == "}sasdfasd\n");

	dessert(td.convert("\\{(Test with closing square bracket) text", "", "") == "{(Test with closing square bracket) text\n");
	dessert(td.convert("\\{( {(Test with closing square bracket) text}", "", "") == "{( text\n");

	dessert(td.convert(" {() #This isn't a title}", "", "") == (" #This isn't a title\n"));
	dessert(td.convert(" {(class) #This isn't a title}", "", "") == (" #This isn't a title\n"));
	dessert(td.convert(" {(class) \n #This is a title \n }", "", "") == (" \n= This is a title \n \n"));
	dessert(throws(td.convert(" {(class)#This isn't a title", "", "")));

	cout << "MULTIPLES UNQUOTED TAGS" << endl;

	dessert(td.convert("[Test with a open square bracket ( also parenthesis and { brackets", "", "") == ("[Test with a open square bracket ( also parenthesis and { brackets\n"));
	dessert(td.convert("[(url) Test with a link ([alternative text] image url)] and {(class) brackets}", "", "") == ("url[Test with a link image::image url[alternative text]] and brackets\n"));
	dessert(td.convert("{(class) [(url) Test with a link ([alternative text] image url)] and brackets}", "", "") == ("url[Test with a link image::image url[alternative text]] and brackets\n"));

	cout << "TABLE" << endl;

	dessert(td.convert("| first cell | second cell |", "", "") == "|=======\n\n| first cell \n| second cell \n\n|=======\n");
	dessert(td.convert("| first cell ", "", "") == "| first cell \n");

	dessert(throws(td.convert("| first cell | second cell ", "", "")));

	dessert(td.convert("| first cell | second cell |\n| third cell | fourth cell |", "", "") == "|=======\n\n| first cell \n| second cell \n\n\n| third cell \n| fourth cell \n\n|=======\n");
	dessert(td.convert("| first cell |\n| second cell | third cell |", "", "") == "|=======\n\n| first cell \n\n\n| second cell \n| third cell \n\n|=======\n");
	dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |", "", "") == "|=======\n\n| first cell \n| second cell \n\n|=======\nText line\n|=======\n\n| third cell \n| fourth cell \n\n|=======\n");
	dessert(td.convert("Text adhoc for testing\n| a | b |\n| c | d |\n", "", "") == "Text adhoc for testing\n|=======\n\n| a \n| b \n\n\n| c \n| d \n\n|=======\n");
	dessert(td.convert("Text adhoc for testing\n| a | b |\n| c | d |\nText adhoc for testing\n", "", "") == "Text adhoc for testing\n|=======\n\n| a \n| b \n\n\n| c \n| d \n\n|=======\nText adhoc for testing\n");

	cout << "END TABLE" << endl;

	dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n#Title1", "", "") == "|=======\n\n| first cell \n| second cell \n\n|=======\nText line\n|=======\n\n| third cell \n| fourth cell \n\n|=======\n= Title1\n");
	dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n__\n--Item\n,,", "", "") == "|=======\n\n| first cell \n| second cell \n\n|=======\nText line\n|=======\n\n| third cell \n| fourth cell \n\n|=======\n\n* Item\n\n");
	dessert(td.convert("__\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n--Item\n,,", "", "") == "\n|=======\n\n| first cell \n| second cell \n\n|=======\nText line\n|=======\n\n| third cell \n| fourth cell \n\n|=======\n* Item\n\n");
	dessert(td.convert("__\n--Item\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n,,", "", "") == "\n* Item\n|=======\n\n| first cell \n| second cell \n\n|=======\nText line\n|=======\n\n| third cell \n| fourth cell \n\n|=======\n\n");
	dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<Test\n", "", "") == "|=======\n\n| first cell \n| second cell \n\n|=======\nText line\n|=======\n\n| third cell \n| fourth cell \n\n|=======\nTest\n");
	dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<+Test\n", "", "") == "|=======\n\n| first cell \n| second cell \n\n|=======\nText line\n|=======\n\n| third cell \n| fourth cell \n\n|=======\nTest\n");
	dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<+Test with pipe |\n", "", "") == "|=======\n\n| first cell \n| second cell \n\n|=======\nText line\n|=======\n\n| third cell \n| fourth cell \n\n|=======\nTest with pipe |\n");

	cout << "NEW LINE" << endl;

	dessert(td.convert("Lorem Ipsum \n ", "", "") == ("Lorem Ipsum \n \n"));
	dessert(td.convert("First line\nLorem Ipsum \n ", "", "") == ("First line\nLorem Ipsum \n \n"));
	dessert(td.convert("First line \nLorem Ipsum \n ", "", "") == ("First line \nLorem Ipsum \n \n"));
	dessert(td.convert("Lorem{(class) Ipsum} \n", "", "") == ("LoremIpsum \n"));

	dessert(td.convert("Lorem\nIpsum\nDolor\n", "", "") == ("Lorem\nIpsum\nDolor\n"));
	dessert(td.convert("{(class) text}\n", "", "") == ("text\n"));
	dessert(td.convert("Lorem\n{(class) text}\nDolor\n", "", "") == ("Lorem\ntext\nDolor\n"));

	cout << "METATAGS" << endl;

	dessert(td.convert("<! Comment commenting things", "", "") == "");

	dessert(td.convert("Text adhoc for testing\n< metatag without space at end\nText adhoc for testing", "", "") == "Text adhoc for testing\n metatag without space at end\nText adhoc for testing\n");
	dessert(td.convert("Text adhoc for testing \n< metatag without space at end\nText adhoc for testing", "", "") == "Text adhoc for testing \n metatag without space at end\nText adhoc for testing\n");
	dessert(td.convert("Text adhoc for testing\n< metatag without space at end\nText adhoc for testing ", "", "") == "Text adhoc for testing\n metatag without space at end\nText adhoc for testing \n");

	dessert(td.convert("Text adhoc for testing\n<+ metatag with space at end\nText adhoc for testing", "", "") == "Text adhoc for testing\n metatag with space at end\nText adhoc for testing\n");

	dessert(td.convert("Text adhoc for testing \n<+ metatag with space at end\nText adhoc for testing", "", "") == "Text adhoc for testing \n metatag with space at end\nText adhoc for testing\n");
	dessert(td.convert("Text adhoc for testing\n<+ metatag with space at end\nText adhoc for testing ", "", "") == "Text adhoc for testing\n metatag with space at end\nText adhoc for testing \n");

	dessert(td.convert("Text adhoc for testing\n<> embed with space at end\nText adhoc for testing ", "", "") == "Text adhoc for testing\n embed with space at end\nText adhoc for testing \n");

	cout << "MISC." << endl;

	dessert(td.convert("alkasdfasdf \n#This isn't a title\nksadjfañlskdfj", "", "")
		== ("alkasdfasdf \n= This isn't a title\nksadjfañlskdfj\n"));

	dessert(td.convert("alkasdfasdf\n#This isn't a title\nksadjfañlskdfj", "", "")
		 == "alkasdfasdf\n= This isn't a title\nksadjfañlskdfj\n");

	dessert(td.convert("Text adhoc for testing\n{(class) container text } Text adhoc for testing ", "", "") == "Text adhoc for testing\ncontainer text  Text adhoc for testing \n");
	dessert(td.convert("Text adhoc for testing \n{(class) container text }\nText adhoc for testing ", "", "") == "Text adhoc for testing \ncontainer text \nText adhoc for testing \n");
	dessert(td.convert("Text adhoc for testing \n{(class) container text}Text adhoc for testing ", "", "") == "Text adhoc for testing \ncontainer textText adhoc for testing \n");

	dessert(td.convert("Paragraph without space at end\n< hello ", "", "") == "Paragraph without space at end\n hello \n");
	dessert(td.convert("Paragraph without space at end\n< hello without space at end\n lsdkjfgsñdlkfjñlk", "", "") == "Paragraph without space at end\n hello without space at end\n lsdkjfgsñdlkfjñlk\n");
	dessert(td.convert("Paragraph without space at end\n< hello ", "", "") == "Paragraph without space at end\n hello \n");
	
}
